<template>
  <div class="pages">
    <keep-alive>
      <router-view class="router-conrainer"></router-view>
    </keep-alive>
    <footer-cmp />
  </div>
</template>
<script>
import FooterCmp from '@/components/footer'
import { getToken } from '@/util/auth'
import { sendCode } from '@/api/my'
export default {
  components: {
    FooterCmp
  },
  data () {
    return {
    }
  },
  created () {
    if (getToken() && !localStorage.getItem('code')) {
      window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx5f929cf10cc579a0&redirect_uri=${encodeURIComponent(
        'https://ddsc.izhixiu.cn/front'
      )}&response_type=code&scope=snsapi_base#wechat_redirect`
      if (window.location.href.includes('?code=')) {
        const code = window.location.href.split('?code=')[1].split('&state')[0]
        localStorage.setItem('code', code)
        this._sendCode(code)
      }
    }
  },
  methods: {
    _sendCode (code) {
      sendCode(code)
        .then(res => {
          console.log(res)
        })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>
<style lang="scss" scoped>
.router-conrainer {
  padding-bottom: 1.22rem;
  background: #f7f7f7;
}
.pages {
}
</style>
